s = ''
m = []
m0 = input().split()
if len(m0) != 3:
    print('Wrong input')
    exit()
for e in m0:
    if e == 'zero':
        s += '0'
    elif e == 'one':
        s += '1'
    elif e == 'two':
        s += '2'
    elif e == 'three':
        s += '3'
    elif e == 'four':
        s += '4'
    elif e == 'five':
        s += '5'
    elif e == 'six':
        s += '6'
    elif e == 'seven':
        s += '7'
    elif e == 'eight':
        s += '8'
    elif e == 'nine':
        s += '9'
s = int(s)
for i in range(s + 1, s + 900):
    f = 0
    for x in range(2, i - 1):
        if i % x == 0:
            f = 1
            break
    if f == 0:
        m.append(i)
    if len(m) == 1:
        break
for i in range(s - 1, s - 900, -1):
    f = 0
    for x in range(2, i - 1):
        if i % x == 0:
            f = 1
            break
    if f == 0:
        m.append(i)
    if len(m) == 2:
        break
if abs(m[0] - s) < abs(m[1] - s):
    print(m[0])
else:
    print(m[1])